package com.zwz.controller;

import com.zwz.dto.BusinessAbnormalityDTO;
import com.zwz.entity.BusinessAbnormality;
import com.zwz.service.BusinessAbnormalityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/business-abnormalities")
public class BusinessAbnormalityController {

    private final BusinessAbnormalityService service;

    @Autowired
    public BusinessAbnormalityController(BusinessAbnormalityService service) {
        this.service = service;
    }

//    @PostMapping
//    public ResponseEntity<?> create(@RequestBody BusinessAbnormality record) {
//        try {
//            service.saveAbnormality(record);
//            return ResponseEntity.status(HttpStatus.CREATED).body(record);
//        } catch (IllegalArgumentException e) {
//            return ResponseEntity.badRequest().body(e.getMessage());
//        }
//    }


    @PostMapping
    public ResponseEntity<?> create( String enterpriseId) {
        try {
            //todo 测试用
//            BusinessAbnormalityDTO dto = service.createWithMain( enterpriseId );
            BusinessAbnormalityDTO dto=new BusinessAbnormalityDTO(null
            ,null);
            return ResponseEntity.status(HttpStatus.CREATED).body(dto);
        } catch (DataIntegrityViolationException e) {
            return ResponseEntity.badRequest().body("数据完整性错误: " + e.getMessage());
        } catch (IllegalArgumentException e) {
            return ResponseEntity.badRequest().body(e.getMessage());
        }
    }



//    @GetMapping("/current")
//    public ResponseEntity<List<BusinessAbnormality>> getCurrent() {
//        return ResponseEntity.ok(service.getCurrentAbnormalities());
//    }
//
//    @GetMapping("/{id}")
//    public ResponseEntity<BusinessAbnormality> getById(@PathVariable Integer id) {
//        BusinessAbnormality info = service.getAbnormalityById(id);
//        return info != null ?
//                ResponseEntity.ok(info) :
//                ResponseEntity.notFound().build();
//    }
}